<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$return=array();
if($_RQ['op']=='get'){
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$nowyue = mktime(0,0,0,date('m'),1,date('Y'));
	$yesyue = mktime(0,0,0,date('m')-1,1,date('Y'));
	$return['htmls']=array();
	if($_SESSION['isfounder'] && 0){
		//超级管理员，显示系统信息，暂不启用
		$return['htmls']=array();
	}elseif($_SESSION['user']['type']==3 ||1){
		//非超级管理员，显示站点信息
		//数据统计
		$access=array();
		$access['wechat_day']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'os'=>2,'createtime >'=>$daytime));
		$access['wxapp_day']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'os'=>1,'createtime >'=>$daytime));
		$access['mobile_day']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'os'=>3,'createtime >'=>$daytime));
		$access['pc_day']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'os'=>4,'createtime >'=>$daytime));
		$access['app_day']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'os'=>5,'createtime >'=>$daytime));
		$access['all_day']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'createtime >'=>$daytime));
		$access['wechat_all']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'os'=>2));
		$access['wxapp_all']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'os'=>1));
		$access['mobile_all']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'os'=>3));
		$access['pc_all']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'os'=>4));
		$access['app_all']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'os'=>5));
		$access['all_all']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2));
		$wechat=array();
		//当日关注
		$wechat['focus_day']=pdo_count('core_fans',array('uniacid'=>$_SESSION['uniacid'],'type'=>2,'follow'=>1,'updatetime >'=>$daytime));
		//总关注
		$wechat['focus_all']=pdo_count('core_fans',array('uniacid'=>$_SESSION['uniacid'],'type'=>2,'follow'=>1));
		//当日取消关注
		$wechat['unfocus_day']=pdo_count('core_fans',array('uniacid'=>$_SESSION['uniacid'],'type'=>2,'follow'=>0,'updatetime >'=>$daytime));
		//总取消关注
		$wechat['unfocus_all']=pdo_count('core_fans',array('uniacid'=>$_SESSION['uniacid'],'type'=>2,'follow'=>0));
		//当日新增粉丝
		$wechat['fans_day']=pdo_count('core_fans',array('uniacid'=>$_SESSION['uniacid'],'type'=>2,'createtime >'=>$daytime));
		//总粉丝
		$wechat['fans_all']=pdo_count('core_fans',array('uniacid'=>$_SESSION['uniacid'],'type'=>2));
		//当日贡献会员
		$wechat['member_day']=pdo_count('core_members',array('uniacid'=>$_SESSION['uniacid'],'from_os'=>2,'createtime >'=>$daytime));
		//总贡献会员
		$wechat['member_all']=pdo_count('core_members',array('uniacid'=>$_SESSION['uniacid'],'from_os'=>2));
		$wxapp=array();
		$wxapp['access_day']=$access['wxapp_day'];
		$wxapp['access_mounth']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'os'=>1,'createtime >'=>strtotime(date('ym'))));
		$wxapp['access_all']=$access['wxapp_all'];
		//当日新增粉丝
		$wxapp['fans_day']=pdo_count('core_fans',array('uniacid'=>$_SESSION['uniacid'],'type'=>1,'createtime >'=>$daytime));
		//总粉丝
		$wxapp['fans_all']=pdo_count('core_fans',array('uniacid'=>$_SESSION['uniacid'],'type'=>1));
		//当日贡献会员
		$wxapp['member_day']=pdo_count('core_members',array('uniacid'=>$_SESSION['uniacid'],'from_os'=>1,'createtime >'=>$daytime));
		//总贡献会员
		$wxapp['member_all']=pdo_count('core_members',array('uniacid'=>$_SESSION['uniacid'],'from_os'=>1));
		//手机端数据
		$mobile=array();
		//当月访问
		$mobile['access_mounth']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'os'=>3,'createtime >'=>strtotime(date('ym'))));
		//总访问
		$mobile['access_all']=$access['mobile_all'];
		//当日贡献会员
		$mobile['member_day']=pdo_count('core_members',array('uniacid'=>$_SESSION['uniacid'],'from_os'=>3,'createtime >'=>$daytime));
		//总贡献会员
		$mobile['member_all']=pdo_count('core_members',array('uniacid'=>$_SESSION['uniacid'],'from_os'=>3));
		//app端数据
		$app=array();
		//当月访问
		$app['access_mounth']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'os'=>5,'createtime >'=>strtotime(date('ym'))));
		//总访问
		$app['access_all']=$access['app_all'];
		//当日贡献会员
		$app['member_day']=pdo_count('core_members',array('uniacid'=>$_SESSION['uniacid'],'from_os'=>5,'createtime >'=>$daytime));
		//总贡献会员
		$app['member_all']=pdo_count('core_members',array('uniacid'=>$_SESSION['uniacid'],'from_os'=>5));
		//pc端数据
		$pc=array();
		//当月访问
		$pc['access_mounth']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'os'=>4,'createtime >'=>strtotime(date('ym'))));
		//总访问
		$pc['access_all']=$access['pc_all'];
		//当日贡献会员
		$pc['member_day']=pdo_count('core_members',array('uniacid'=>$_SESSION['uniacid'],'from_os'=>4,'createtime >'=>$daytime));
		//总贡献会员
		$pc['member_all']=pdo_count('core_members',array('uniacid'=>$_SESSION['uniacid'],'from_os'=>4));
		//月份
		for($i=0;$i<12;$i++){
			if($i==0){
				$yuestart = mktime(0,0,0,date('m'),1,date('Y'));
				$yueend = time();
				
			}else{
				$yuestart = mktime(0,0,0,date('m')-$i,1,date('Y'));
				$yueend = mktime(0,0,0,date('m')-$i+1,1,date('Y'));
			}
			$params=array('uniacid'=>$_SESSION['uniacid']);
			$params['createtime between']=array($yuestart,$yueend);
			$paramswxapp['from_os']=3;
			$paramswxapp['createtime between']=array($yuestart,$yueend);
			$month12[] = date('Y-m',strtotime(-$i.' month'));
			//$monthaccess[]=pdo_count('core_access_log',$params);
			$monthfens[]=pdo_count('core_members',$params);
			$monthwxappfens[]=pdo_count('core_members',$paramswxapp);
			//$monthcredit2[]=pdo_getsum('core_members',$params,'credit2');
		}
		$month12=array_reverse($month12);
		$site=pdo_get('core_accounts',array('uniacid'=>$_SESSION['uniacid']),array('title','logo','desc','ewm','credit2','endtime','groupid','opendiys'));
		if($site['groupid']){
			$group=pdo_get('core_account_group',array('id'=>$site['groupid']));
		}
		$applist=array(
				array('name'=>'core','id'=>'wechat','title'=>'四合一公众号','desc'=>'一键DIY制作小程序','icon'=>'fa-weixin','color'=>'#63BE72','action'=>'/wechat.list/list/','openaction'=>'/account.siteinfo/group_item/','price'=>$app_prices['wechat']),
				array('name'=>'core','id'=>'wxapp','title'=>'微信小程序','desc'=>'一键DIY制作小程序','icon'=>'fa-jsfiddle','color'=>'#63BE72','action'=>'/wxapp.list/get/type=8','openaction'=>'/account.siteinfo/group_item/','price'=>$app_prices['wxapp']),
				array('name'=>'core','id'=>'ttapp','title'=>'头条/抖音小程序','desc'=>'引爆抖音流量王','icon'=>'fa-pinterest','color'=>'#FF547B','action'=>'/wxapp.list/get/type=8','openaction'=>'/account.siteinfo/group_item/','price'=>$app_prices['ttapp']),
				array('name'=>'core','id'=>'aliapp','title'=>'支付宝小程序','desc'=>'依托天猫/淘宝变现','icon'=>'fa-facebook-square','color'=>'#4491F1','action'=>'/wxapp.list/get/type=8','openaction'=>'/account.siteinfo/group_item/','price'=>$app_prices['aliapp']),
				array('name'=>'core','id'=>'baiduapp','title'=>'百度小程序','desc'=>'搜索SEO内容王','icon'=>'fa-behance-square','color'=>'#7783EA','action'=>'/wxapp.list/get/type=8','openaction'=>'/account.siteinfo/group_item/','price'=>$app_prices['baiduapp']),
				array('name'=>'core','id'=>'qqapp','title'=>'QQ小程序','desc'=>'个性QQ轻应用','icon'=>'fa-qq','color'=>'#FF4444','action'=>'/wxapp.list/get/type=8','openaction'=>'/account.siteinfo/group_item/','price'=>$app_prices['qqapp']),
				array('name'=>'core','id'=>'mobile','title'=>'H5微官网','desc'=>'一键DIY制作微官网','icon'=>'fa-mobile','color'=>'#63BE72','action'=>'/website.mobile_web/list/','openaction'=>'/account.siteinfo/group_item/','price'=>$app_prices['mobile']),
				array('name'=>'core','id'=>'pc','title'=>'PC官网建站','desc'=>'一键DIY制作PC网','icon'=>'fa-windows','color'=>'#FCC600','action'=>'website.pc_web/','openaction'=>'/account.siteinfo/group_item/','price'=>$app_prices['pc']),
				array('name'=>'core','id'=>'xiu','title'=>'微场景','desc'=>'一键DIY制作场景宣传单','icon'=>'fa-dropbox','color'=>'#C3A769','action'=>'jy_xiu/list/','openaction'=>'/account.siteinfo/group_item/','price'=>$app_prices['xiu']),
				array('name'=>'core','id'=>'h5game','title'=>'互动营销','desc'=>'一键创建H5营销活动','icon'=>'fa-google-plus','color'=>'#FF547B','action'=>'jy_h5game/index/','openaction'=>'/account.siteinfo/group_item/','price'=>$app_prices['h5game']),
		);
		foreach($applist as $key=>&$item){
				if(strpos($group['noshow_app'],';'.$item['id'].';') !== false){
					unset($applist[$key]);
				}
				if(strpos($group['noshow_app'],';wxapp;') !== false && ($item['id']=='ttapp' || $item['id']=='aliapp' || $item['id']=='baiduapp' || $item['id']=='qqapp')){
					unset($applist[$key]);
				}
				if(strpos($site['opendiys'],';'.$item['id'].';') !== false || $item['id']=='wechat' || $item['id']=='mobile'){
					$item['isclosed']=false;
				}else{
					if(!$_SESSION['isfounder']){
						$item['isclosed']=true;
					}
				}
		}
		$intypes=get_plugin_intypes();
		$inlist=array();
		foreach($intypes as $k=>&$inv){
			if($k){
				$inlist[$k]['name']='core';
				$inlist[$k]['title']=$inv;
				$inlist[$k]['action']='/account.apphome//type='.$k;
			}else{
				$inlist[18]['name']='core';
				$inlist[18]['title']=$inv;
				$inlist[18]['action']='/account.apphome//type=0';
			}
		}
		$htmls=array(
				array('type'=>'data','tpltype'=>8,'title'=>'常用平台_Commonly used products','datas'=>$applist),
				//array('type'=>'data','tpltype'=>5,'title'=>'选择行业_Commonly used products','datas'=>$inlist),
				array('type'=>'data','tpltype'=>1,'one_num'=>4,'title'=>'站点今日/总访问数据指标_site today/all data','datas'=>array(
					array('title'=>'公众号数据','icon'=>'fa-weixin','num'=>2,'data'=>array($access['wechat_day'],$access['wechat_all'])),
					array('title'=>'小程序数据','icon'=>'fa-cloud','bgcolor'=>'#009933','num'=>2,'data'=>array($access['wxapp_day'],$access['wxapp_all'])),
					array('title'=>'手机端数据','icon'=>'fa-apple','bgcolor'=>'#3366FF','num'=>2,'data'=>array($access['mobile_day'],$access['mobile_all'])),
					array('title'=>'PC端数据','icon'=>'fa-windows','bgcolor'=>'#FF3300','num'=>2,'data'=>array($access['pc_day'],$access['pc_all'])),
				)),
				array('type'=>'echarts_arealine','width'=>'50%','ecid'=>'mobile','title'=>'粉丝会员数据指标_fans user data','datas'=>array(
					'datas'=>array(
						array('name'=>'H5粉丝数','value'=>$monthfens),
						array('name'=>'小程序粉丝数','value'=>$monthwxappfens),
					),
					'xdatas'=>$month12,
				)),
				array('type'=>'data','tpltype'=>2,'one_num'=>2,'width'=>'50%','padding'=>'66px 0 0 0','title'=>'站点今日访问指标_site today access data','datas'=>array(
					array('title'=>'公众号数据','num'=>2,'data'=>array($access['wechat_day'],$access['wechat_all'])),
					array('title'=>'小程序数据','num'=>2,'data'=>array($access['wxapp_day'],$access['wxapp_all'])),
					array('title'=>'手机端数据','num'=>2,'data'=>array($access['mobile_day'],$access['mobile_all'])),
					array('title'=>'PC端数据','num'=>2,'data'=>array($access['pc_day'],$access['pc_all'])),
					array('title'=>'APP端数据','num'=>2,'data'=>array($access['app_day'],$access['app_all'])),
					array('title'=>'总访问量','num'=>2,'data'=>array($access['all_day'],$access['all_all'])),
				)),
				array('type'=>'data','tpltype'=>4,'one_num'=>4,'title'=>'站点今日/总访问数据指标_site today/all access data','datas'=>array(
					array('title'=>'公众号数据','num'=>2,'data'=>array($access['wechat_day'],$access['wechat_all'])),
					array('title'=>'小程序数据','bgcolor'=>'#009933','num'=>2,'data'=>array($access['wxapp_day'],$access['wxapp_all'])),
					array('title'=>'手机端数据','bgcolor'=>'#3366FF','num'=>2,'data'=>array($access['mobile_day'],$access['mobile_all'])),
					array('title'=>'PC端数据','bgcolor'=>'#FF3300','num'=>2,'data'=>array($access['pc_day'],$access['pc_all'])),
				)),
				array('type'=>'echarts_pie','one_num'=>2,'width'=>'50%','ecid'=>'wechat','title'=>'公众号数据指标_wechat data','datas'=>array(
					'time' => date("Y-m-d H:i:s", time()),
					'datas'=>array(
						array('name'=>'总关注','value'=>$wechat['focus_all']),
						array('name'=>'小程序数据','value'=>$wechat['unfocus_all']),
						array('name'=>'手机端数据','value'=>$wechat['fans_all']),
						array('name'=>'PC端数据','value'=>$wechat['member_all']),
					),
				)),
				array('type'=>'echarts_pie','one_num'=>2,'width'=>'50%','ecid'=>'wxapp','title'=>'小程序数据指标_wxapp data','datas'=>array(
					'time' => date("Y-m-d H:i:s", time()),
					'datas'=>array(
						array('name'=>'总访问量','value'=>$wxapp['access_all']),
						array('name'=>'当月访问量','value'=>$wxapp['access_mounth']),
						array('name'=>'总粉丝数','value'=>$wxapp['fans_all']),
						array('name'=>'PC端数据','value'=>$wxapp['member_all']),
					),
				)),
				/*
				array('type'=>'echarts_bar','num'=>12,'ecid'=>'pc','title'=>'PC端数据年报指标','datas'=>array(
					'datas'=>array(
						array('name'=>'访问量','value'=>array(8,8,11,12,14,16,18,55,33,22,12,56)),
						array('name'=>'粉丝数','value'=>array(8,8,11,12,14,16,18,55,33,22,12,56)),
						array('name'=>'PC端数据','value'=>array(8,8,11,12,14,16,18,55,33,22,12,56)),
					),
					'xdatas'=>array("1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"),
				)),*/
		);
	}
	$system=core_setting('site');
	$site['share_url']= SITEROOT.'./manage/index.php?plugin=core&action=account.welcome&uid='.$_SESSION['uniacid'];
	if($site['groupid']){
		$site['grouptitle']=$group['title'];
		$site['resource']=$group['resource'];
		$is_legao=pdo_getcolumn('core_plugins',array('name'=>$group['plugin_name']),'is_legao');	
	}
	if($system['guide_group']!=1 && !$is_legao && !$_SESSION['isfounder'] && $_SESSION['user']['type']==3){
		array_unshift($htmls,array('type'=>'guide_modal','tpltype'=>1,'title'=>'常用产品'));
	}
	$quicks=pdo_getall('core_user_quick',array('uid'=>$_SESSION['uid']),array('id','action','op','plugin','title','query','html'),'','id desc');
	if($quicks){
			foreach($quicks as &$quick){
				$quick=array('id'=>$quick['id'],'title'=>$quick['title'],'url'=>array('action'=>$quick['action'],'op'=>$quick['op'],'plugin'=>$quick['plugin'],'query'=>$quick['query'],'title'=>$quick['title'],'html'=>$quick['html']));
			}
		array_unshift($htmls,array('type'=>'list_menu','title'=>'快捷操作_shortcuts','menus'=>$quicks,'del'=>true));
	}
	$iswechat=pdo_getcolumn('core_account_wechat',array('uniacid'=>$_SESSION['uniacid']),'id');
	if($_SESSION['os']=='windows'){
		if($_SESSION['isfounder'] && (empty($system['title']) || empty($system['name']))){
			$htmls[]=array('type'=>'intro','title'=>'新手引导','datas'=>array(
				array('element'=>'#top_nav_item_0','intro'=>'创始人您好！您还没有设置好系统页面信息(简称/标题)噢！</br>只有设置好了平台，才能有好的驰骋！点这里开始噢！','position'=>''),
			));
		}elseif(empty($site['title'])){
			$htmls[]=array('type'=>'intro','title'=>'新手引导','datas'=>array(
				array('element'=>'#top_nav_item_1','intro'=>'主人您好！您还没有设置好站点信息噢！</br>只有设置好了信息，才能有好的体验！点站点设置->基本设置！','position'=>''),
			));
		}elseif($_SESSION['uniacid']==1 && empty($iswechat)){
			$htmls[]=array('type'=>'intro','title'=>'新手引导','datas'=>array(
				array('element'=>'#top_nav_item_2','intro'=>'创始人您好！您还没有添加默认公众号噢！</br>这点很重要，是激活平台,实现扫码登录，粉丝同步的关键！点应用端->公众号管理！','position'=>''),
			));
		}elseif(empty($iswechat)){
			$htmls[]=array('type'=>'intro','title'=>'新手引导','datas'=>array(
				array('element'=>'#top_nav_item_2','intro'=>'主人您好！您还没有添加默认公众号噢！</br>添加了默认有效的公众号，才能实现扫码登录，粉丝同步，微信支付等体验！点应用端->公众号管理！','position'=>''),
			));
		}
	}
	if($_SESSION['os']!='windows'){
		if($site['endtime'] && $site['endtime']<time()){
			$site['status']=2;
		}elseif($site['endtime']>time()){
			$site['status']=1;
		}elseif(!$site['endtime']){
			$site['status']=1;
		}
		$site['endtime']=$site['endtime']?date('Y-m-d',$site['endtime']):'长期有效';
		//总贡献会员
		$site['member_all']=pdo_count('core_members',array('uniacid'=>$_SESSION['uniacid']));
		//总贡献会员
		$site['access_all']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid']));
		$site['uniacid']=$_SESSION['uniacid'];
		$return['applist']=$applist;
	}
		$fields=array('id','title','paixu','status','group_id','content','type');
		$pindex = max(1, intval($_RQ['page']));
		$psize = 8;
		$orderby=' id desc';
		$total='';
		$return['notice']=pdo_getslice('core_article',array('status'=>1,'type'=>2),array($pindex,$psize), $total,$fields,'',$orderby);
		$operating=core_setting('operating');
		$return['site']=$site;
		$return['operating']=$operating;
		$return['access']=$access;
		$return['wechat']=$wechat;
		$return['wxapp']=$wxapp;
		$return['mobile']=$mobile;
		$return['pc']=$pc;
		set_html('title','系统后台');
		set_html('header','common/header');
		if($_SESSION['os']=='windows'){
			$return['htmls']=$htmls;
		}
		exi($return);
}
if($_RQ['op']=='add_quick'){
	$postdata=get_postdata();
	$data=array(
		'uid'=>$_SESSION['uid'],
		'action'=>trim($postdata['action']),
		'plugin'=>trim($postdata['plugin']),
		'op'=>trim($postdata['op']),
		'query'=>trim($postdata['query']),
		'title'=>trim($postdata['title']),
		'html'=>trim($postdata['html'])
	);
	pdo_insert('core_user_quick',$data);
	$id=pdo_insertid();
	$res=array('id'=>$id,'type'=>'success');
	exi($res);
}
if($_RQ['op']=='set_quick'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		if(!$id){
			exi('请先设置要保存的快捷方式！','error');
		}
		$update=array_fields(array('title'),$post);
		pdo_update('core_user_quick',$update,array('id'=>$id,'uid'=>$_SESSION['uid']));
		exi('操作成功！');
	}
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要设置的快捷方式！','error');
	}
	$item=pdo_get('core_user_quick',array('id'=>$id,'uid'=>$_SESSION['uid']),array('id','title'));
	if(!$item){
		exi('要编辑设置的快捷方式不存在！','error');
	}
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'edit'=>array(
			array('type'=>'string','name'=>'title','title'=>'快捷方式名称'),
		),
	);
	exi($return);
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('core_user_quick',array('id'=>$id,'uid'=>$_SESSION['uid']));
	}
	exi('删除成功！');
}
if($_RQ['op']=='getintype'){
	$intypes=get_plugin_intypes();
	$inlist=array();
	foreach($intypes as $k=>&$inv){
			if($k){
				$inlist[$k]['title']=$inv;
			}else{
				$inlist[18]['title']=$inv;
			}
	}
	foreach($inlist as $k=>&$ig){
			$groups=pdo_getall('core_account_group');
			foreach($groups as $kg=>&$gg){
				$intype=pdo_getcolumn('core_plugins',array('name'=>$gg['plugin_name']),'intype');
				if($k==$intype){
					$ig['groups'][]=$gg;
				}
			}
	}
	$return['list']=$inlist;
	exi($return);
}
?>